<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@include file="/pageRc/common/common.jsp" %>

<!DOCTYPE html>
<html lang="en" style="overflow-x: hidden">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="msapplication-tap-highlight" content="no">
    <link rel="stylesheet" href="<%=commonPath %>/pageRc/layui/css/layui.css" media="all">
    <script type="text/javascript" src="<%=commonPath %>/pageRc/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="<%=commonPath %>/pageRc/common/utils.js"></script>
    <script type="text/javascript" src="<%=commonPath %>/pageRc/common/msgTool.js"></script>
    <script type="text/javascript" src="<%=commonPath %>/pageRc/layui/layui.js"></script>
    <title>团队管理</title>

    <script>
        $(function () {
        })
        //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
        layui.use('element', function () {
            var element = layui.element();
            //…
        });
    </script>
</head>
<body class="layui-main">
<blockquote class="layui-elem-quote">
    团队信息列表
</blockquote>
<div class="layui-form-item ">
    <form id="createMsgForm" name="createMsgForm" class="layui-form"
          action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-inline">
                    <select name="proGroupNo" id="proGroupNo" lay-filter="proGroupSelect">
                        <c:forEach items="${groupList}" var="group">
                            <option value="${group.proGroupNo}">${group.proGroupName}</option>
                        </c:forEach>
                    </select>
                </div>
                <div class="layui-inline">
                    -
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" type="button" data-method="doSearchSum" id='searchbutton'>查询</button>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" type="button" onclick="addGroup()">新增</button>
                </div>
            </div>
        </div>
        <div class="layui-form-item" id="dateDiv">
            <div class="layui-inline">
                <table class="layui-table" lay-even="" lay-skin="line" style="text-align: center;">
                    <colgroup>
                        <col width="140">
                        <col width="140">
                        <col width="240">
                    </colgroup>
                    <thead>
                    <tr>
                        <th style="text-align: center">团队名称</th>
                        <th style="text-align: center">经理</th>
                        <th style="text-align: center">操作</th>
                    </tr>
                    </thead>
                    <tbody id="detailDiv">
                    </tbody>
                    <script id="tplSrc" type="text/html">
                        {{#  layui.each(d.groupList, function(index, x){}}
                        <tr>
                            <td>{{x.proGroupName==undefined?'':x.proGroupName}}</td>
							<td>{{x.groupManger==undefined?'':x.groupManger}}</td>
                            <td>
                                <button class="layui-btn" type="button" onclick="updateGroup('{{x.proGroupNo}}')">更新</button>
								<button class="layui-btn" type="button" onclick="deleteGroup('{{x.proGroupNo}}')">删除</button>
							</td>
                        </tr>
                        {{#  }); }}
                    </script>
                </table>
            </div>
        </div>
<div class="layui-form-item">
				<div class="layui-inline">
					<div id="laypageDiv"></div>
				</div>
			</div><button style="margin: 0px;"></button>
    </form>
</div>
<input id="totalNum" type="hidden" name="totalNum" >
</body>
<script type="text/javascript">
    var path = "<%=commonPath%>";
    var msg = new msgTool();
    layui.use(
        ['form', 'layer', 'laytpl', 'laypage', 'laydate'],
        function () {
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            var form = layui.form()
                , layer = layui.layer
                , laypage = layui.laypage
                , laytpl = layui.laytpl;

            var active = {
            		doSearchSum : function() { //搜索
			      	    	active.doSearchDetail(1); 
			         }
			         ,doSearchDetail:function(v_curr){ //搜索   
			         if(v_curr==1){
			      	    var getTpl = tplSrc.innerHTML;
			  			var dataObj = {
			  						"startRow" : (v_curr-1)*5,
			  						"pageSize" : 5,
			  						"proGroupNo": $("#proGroupNo").val(),
			                        "proGroupName": $("#proGroupName").val()
			  					};
			  			msg.sendMsg("/page/sys/searchGroupInfor.do",dataObj,function(data) {
			  				console.log(data);
			  				laytpl(getTpl).render(data.body,function(html) {
			  				    detailDiv.innerHTML = html;
			  					$('#totalNum').val(data.body.count)
			  				});
			  				totalNum = Math.ceil(data.body.count/5);
			  				laypage({
				                 cont: 'laypageDiv'
				                 ,pages:totalNum
				                  ,jump: function(obj,first){
				                	  if(first!=true){
				                	  	active.doSearchDetail(obj.curr); 
				                	  }
				                   } 
				                 }); 
			  			}); 
			         }else{
			        	  var getTpl = tplSrc.innerHTML;
				  			var dataObj = {
				  						"startRow" : (v_curr-1)*5,
				  						"pageSize" : 5,
				  						"proGroupNo": $("#proGroupNo").val(),
				                        "proGroupName": $("#proGroupName").val()
				  					};
				  			msg.sendMsg("/page/sys/searchGroupInfor.do",dataObj,function(data) {
				  				laytpl(getTpl).render(data.body,function(html) {
				  				    detailDiv.innerHTML = html;
				  					$('#totalNum').val(data.body.count)
				  				});
				  				totalNum = Math.ceil(data.body.count/5);
				  				
				  			}); 

			         }
			      	   
			         }
              
            };
            $('#searchbutton').on('click', function () {
                var othis = $(this), method = othis.data('method');
                active[method] ? active[method].call(this, othis) : '';
            });
           
        });

    function deleteGroup(proGroupNo) {
        var jsonDate = {};
        jsonDate.proGroupNo = proGroupNo;
        layer.confirm("你确定要删除这个团队信息吗？。",{icon:3,title:"提示"},function(index){
        	  msg.sendMsg("/page/sys/deleteSingleGroup.do", jsonDate, function (data) {
                  var rsObj = null;
                  if (msg.isJson(data)) {
                      rsObj = data
                  } else {
                      rsObj = JSON.parse(data);
                  }
                  var retCode = rsObj.head.retCode;
                  if (retCode !== '0000') {
                      layer.alert("删除失败！");
                  } else {
                      flush();
                      layer.alert("删除成功！");
                  }
              });
        });
    }

    function updateGroup(proGroupNo) {
        layer.open({
            type: 2,
            title:"团队信息维护",
            area: ['500px', '420px'],
            scrollbar: false,
            content: '<%=commonPath %>/page/sys/'+proGroupNo+'/selectSingleGroup.do',
            success: function (layero, index) {
            },
            end: function () {
            }
        });
    }
    function addGroup(){
    	layer.open({
    		 type: 2,
             title:"新增团队",
             area: ['500px', '420px'],
             scrollbar: false,
             content: '<%=commonPath %>/page/sys/AddGroup/report.do',
             success: function (layero, index) {
             },
             end: function () {
             }
    	})
    }
    function flush(){
        $('#searchbutton').click()
    }

</script>
</html>